<template>
	<view>

		<!-- 导航栏 -->
		<view class="box-main-top" :style="{ height: homeTop+88 + 'rpx' }">
			<!-- 导航栏 -->
			<view class="head-wrapper" id="home" :style="{ top: homeTop + 'rpx' }">
				<image class="box-logo " src="https://yjgs.jsonbug.com/test/yjgs_logo.png"></image>
			</view>
			<!-- end -->
		</view>
		<!-- end -->

		<view :style="{ height: homeTop+88 + 'rpx' }">
		</view>

		<!-- 导航栏 -->
		<u-sticky :offsetTop='homeTop'>
			<view class="tab-container">
				<view class="tab-item" :class="{'active': activeTab === 0}" @click="switchTab(0)">
					商机广场
					<view class="tab-line" v-if="activeTab === 0"></view>
				</view>
				<view class="tab-item" :class="{'active': activeTab === 1}" @click="switchTab(1)">
					贵商人脉
					<view class="tab-line" v-if="activeTab === 1"></view>
				</view>
			</view>
		</u-sticky>
		<!-- end -->

		<!-- 分类 -->
		<view class="box-fl">

			<!-- 搜索框 -->
			<view class="search-box">
				<input v-model="searchVal" @input="inputChange" type="text" class="search-input" placeholder="输入搜索内容" />
				<image @click="toMyCard" v-if="activeTab == 1" class="ml-20"
					src="https://yjgs.jsonbug.com/test/cjmp.png" style="width: 320rpx;height: 94rpx;"></image>
			</view>
			<view class="tab-content">

				<view v-if="activeTab === 0">
					<view v-for="(item,index) in sendList" :key="index" class="m-20 bg-white bb p-20 br-20 ">
						<view class="flex ac sb">
							<view @click.stop="toDescPage(item)" class="flex">
								<view>
									<image class="br-100p" :src="item.avatar" mode="aspectFill"
										style="width: 80rpx;height: 80rpx;">
									</image>
								</view>
								<view class="ml-10 mt-5">
									<view>
										<text class="fw fs-30">{{item.name || ''}}</text>
										<text class="ml-10 mr-10">/</text>
										<text class="fs-24 c-666">{{item.position || ''}}</text>
										<text v-if="item.is_real == 2" class="iconfont-yjgs c-999 ml-10">&#xe6eb;</text>
										<text v-if="item.is_real == 1" class="iconfont-yjgs ml-10"
											style="color: #00009E;">&#xe6eb;</text>
									</view>
									<view class="c-999 mt-5 fs-24 line-1">
										{{item.company_name || ''}}
									</view>
								</view>
							</view>
							<navigator :url="'/pages/extend/connection/index_desc?id='+item.card_id" hover-class="none">
								<view class="box-fast">
									立即联系
								</view>
							</navigator>
						</view>
						<view class="mt-10" style="margin-left: 90rpx;">
							<view class="flex ac">
								<view v-if="item.type == 2" class="box-xq">
									需求
								</view>
								<view v-else class="box-xq"
									style="background-color: #FFE7E6;color: #D22C25;border: 1rpx solid #D22C25;">
									供应
								</view>
								<view class="fw fs-30 ml-10 line-2" style="width: 80vw;">
									{{item.title || ''}}
								</view>
							</view>
							<view class="mt-10 ">
								<u-read-more toggle :showHeight='140' textIndent='0em'>
									<view>
										<text class="fs-28">
											{{item.content}}
										</text>
									</view>
								</u-read-more>
							</view>
							<view v-if="item.images" class="mt-20 box-img-for">
								<view @click="$timer.preView($timer.strToArr($timer.ensureUrl(item.images)),_index)"
									v-for="(obj,_index) in $timer.strToArr($timer.ensureUrl(item.images))" :key="_index"
									class="mb-5 mr-15">
									<image class="br-6" style="height: 160rpx;width: 160rpx;" :src="obj"
										mode="aspectFill">
									</image>
								</view>
							</view>
							<view class="flex ac mt-20">
								<view class="mr-50">
									<text class="fs-24 c-999">{{$timer.formatTime(item.create_time) || ''}}</text>
								</view>
								<view class="ml-30">
									<text class="iconfont icon-pinglun3"></text>
									<text class="ml-5 fs-24">{{item.comment_num || 0}}</text>
								</view>
								<view v-if="item.is_follow == 2" @click="followClick('收藏',item)" class="ml-50">
									<text class="iconfont icon-shoucang2"></text>
									<text class="ml-5 fs-24">{{item.follow_num || 0}}</text>
								</view>
								<view v-if="item.is_follow == 1" @click="followClick('取消收藏',item)" class="ml-50">
									<text class="iconfont-yjgs fs-32" style="color: #FBC11A;">&#xe62a;</text>
									<text class="ml-5 fs-24">{{item.follow_num || 0}}</text>
								</view>
								<view @click="cardCardInfoLikeFunc(item)" class="ml-50">
									<text class="iconfont icon-dianzan1"></text>
									<text class="ml-5 fs-24">{{item.like_num || 0}}</text>
								</view>
								<view @click="extendClick(item)" class="ml-50 box-moreM">
									<text class="iconfont icon-gengduo1"></text>
								</view>
							</view>
							<view v-if="item.comment.length > 0" class="mt-20  bb p-10 fs-24"
								style="background-color: #F5F5F5;">
								<view @click="replyCommont(item,cur)" v-for="(cur,_ind) in item.comment" :key="_ind"
									class="mb-10">
									<text style="color: #00009E;" class="fw">{{cur.user.nickname || ''}}</text>
									<text v-if="!cur.re_uid" class="mr-5">:</text>
									<text v-if="cur.re_uid" class="ml-5 ml-5">回复</text>
									<text v-if="cur.re_uid" style="color: #00009E;"
										class="fw ">{{cur.reuser.nickname || ''}}：</text>
									<text>{{cur.content || ''}}</text>
								</view>
							</view>
						</view>
					</view>

					<!-- 空数据站位 -->
					<emptyPage v-if="sendList.length == 0" style="margin-top: 0rpx;margin-bottom: 20rpx;">
					</emptyPage>
					<!-- end -->

					<!-- 加载更多 -->
					<uni-load-more v-if="sendList.length > 0" :status="status" />
					<!-- end -->

					<!-- 供需对接 扩展 -->
					<u-action-sheet @select='sheetSelect' cancelText='取消' round='12' @close='sheetClose'
						closeOnClickOverlay safeAreaInsetBottom :actions="sheetList" :show="sheetShow"></u-action-sheet>
					<!-- end -->

					<!-- 弹窗输入(供需对接 评论) -->
					<u-popup :show="popupShow" @close="popupShow=false;popupFocus=false">
						<view class="p-20 flex ac">
							<view class="w-100p">
								<u--input :focus='popupFocus' :cursorSpacing='120' :placeholder="placeholder"
									border="surround" v-model="inputValu"></u--input>
							</view>
							<view v-if="popupShow" @click="sendCommonClick" class="sentCommon">
								发送
							</view>
						</view>
					</u-popup>
					<!-- end -->

					<!-- 供需发布 -->
					<!-- <view @click="toPageClick" class="box-gxfb">
						<image src="https://db.jsonbug.com/icon/fasong.png" mode="aspectFill"
							style="width: 120rpx;height: 120rpx;"></image>
					</view> -->
					<!-- end -->
				</view>

				<!-- 贵商人脉内容 -->
				<view v-if="activeTab === 1">
					<view class="flex ww">
						<view @click="toMpPage(item)" v-for="(item,index) in cardDataList" :key="index"
							class="box-mp bb " style="background-color: white;">
							<view class="pos-r">
								<view>
									<image mode="aspectFill" :src="$timer.ensureUrl(item.avatar)"
										style="width:100%;height:393rpx;border-top-right-radius: 10rpx;border-top-left-radius: 10rpx;">
									</image>
								</view>
								<view v-if="item.is_real == 1" class="pos-a" style="top: 20rpx;left: 20rpx;">
									<image src="https://yjgs.jsonbug.com/test/shiming.png"
										style="width: 116rpx;height: 49rpx;">
									</image>
								</view>
								<view class="box-mp-name c-white">
									<view class="fw fs-32 ">
										{{item.name || '--'}}
									</view>
									<view class="box-mp-rq tc">
										<text class="iconfont-yjgs c-red">&#xe604;</text>
										<text style="color: #0012AA;font-size: 24rpx;">人气值:{{item.pv || ''}}</text>
									</view>
								</view>
							</view>
							<view class="c-000 fs-24 tc fw">
								<view class="mt-10 line-1">
									{{item.company_name || ''}}
								</view>
								<view class="mt-10">
									{{item.position || ''}}
								</view>
							</view>
						</view>
					</view>
					<!-- 加载更多 -->
					<uni-load-more v-if="cardDataList.length > 0" :status="mpStatus" />
					<!-- end -->
				</view>

			</view>
		</view>
		<!-- end -->


		<!-- 我的名片 -->
		<view v-if="activeTab == 1" @click="toMycardPage" class="box-create shadow-2" style="z-index: 999;">
			<text class="iconfont-yjgs">
				&#xe65d;
			</text>
			<text class="ml-10 pos-r" style="top: -2rpx;">我的名片</text>
		</view>
		<!-- end -->

		<!-- 贵商广场 -->
		<view v-if="activeTab == 0" @click="toPageClick" class="box-create shadow-2" style="z-index: 999;">
			<text class="iconfont-yjgs">
				&#xe886;
			</text>
			<text class="ml-10 pos-r" style="top: -2rpx;">发布供需</text>
		</view>
		<!-- end -->

		<!-- 回到顶部 -->
		<image @click="onTopScrollClick" v-if="scrollTop > 200 && activeTab == 1" class="pos-f"
			src="https://yjgs.jsonbug.com/test/top.png" style="width: 130rpx;height: 130rpx;right: 0;bottom: 360rpx;">
		</image>
		<!-- end -->

		<!--自定义底部tab-->
		<customTab :newData="newData" :activeRouter="activeRouter"></customTab>

	</view>
</template>

<script>
	import customTab from '@/components/customTab';
	import {
		getNavigation
	} from '@/api/public.js';
	import Cache from '@/utils/cache.js';
	import {
		mapGetters
	} from "vuex";
	import {
		configMap
	} from "@/utils";
	import {
		cardList,
		cardCardInfoLike,
		cardUserGetCardStatus,
		cardCardInfoList,
		projectCommentCreate,
		projectCommentDelete,
		cardRelationCreate,
		cardRelationDelete
	} from '@/api/extend.js'
	import {
		toLogin
	} from '@/libs/login.js';
	export default {
		components: {
			customTab,
		},
		data() {
			return {
				path: '/pages/connection/index_v2',
				activeRouter: '',
				newData: {},
				searchVal: '',
				homeTop: 88,
				activeTab: 1, // 默认显示贵商人脉
				scrollTop: 0,

				cardDataList: [], // 名片列表
				cardPage: 1,
				// 随机分页优化相关变量 - 解决后端随机查询重复数据问题
				displayedCardIds: [], // 已显示的名片ID集合，用于前端去重
				requestedPages: [], // 已请求的页码集合，避免重复请求同一页
				totalPages: 10, // 估算总页数，会根据返回数据动态调整
				noNewDataCount: 0, // 连续无新数据次数，用于判断是否到底

				current_page: 1,
				inputValu: '',
				sheetList: [{
						name: '评论',
					},
					// {
					// 	name: '转发',
					// 	openType: 'share'
					// },
				],
				sheetShow: false,
				placeholder: '请输入内容！',
				popupShow: false,
				popupFocus: false,
				sendList: [],
				status: 'loading', // more loading noMore
				mpStatus: 'loading', // more loading noMore
				sendPage: {
					current_page: 1,
				},
				form: {
					search: ''
				},
			}
		},
		watch: {
			activeTab(newVal, newOld) {
				uni.setStorageSync('tabberQuery', {
					index: 1,
					data: newVal
				})
			}
		},
		computed: configMap({}, mapGetters(['isLogin', 'uid', 'userInfo'])),
		onPageScroll(e) {
			uni.$u.debounce(this.toNextClick(e.scrollTop), 1000)
		},
		methods: {
			toNextClick(e) {
				this.scrollTop = e;
			},
			onTopScrollClick() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				})
			},
			toMycardPage() {
				if (!this.isLogin) {
					toLogin();
					return
				}
				this.$timer.toMyCardPage();
			},
			toDescPage(item) {
				uni.navigateTo({
					url: '/pages/extend/connection/chamber_desc?id=' + item.id
				})
			},
			getNav() {
				getNavigation().then(res => {
					this.newData = res.data;
					if (this.newData.status && this.newData.status.status) {
						uni.hideTabBar()
					} else {
						uni.showTabBar()
					}
				})
			},
			inputChange(e) {
				if (this.activeTab == 0) { //商机广场
					uni.$u.debounce(this.cardCardInfoListSearchFunc(), 500)
				}

				if (this.activeTab == 1) { // 贵商人脉
					uni.$u.debounce(this.getListSearch(), 500)
				}
			},
			toMyCard() {
				uni.navigateTo({
					url: '/pages/extend/connection/create'
				})
			},
			
			// 生成随机页码，避免重复请求同一页
			generateRandomPage() {
				// 确保totalPages至少为1
				if (this.totalPages < 1) {
					this.totalPages = 1;
				}
				
				// 如果已经请求了所有页码，不重置，让上层逻辑判断是否结束
				if (this.requestedPages.length >= this.totalPages) {
					// 所有页码都请求过了，随机返回一个页码（用于可能的重复数据检测）
					return Math.floor(Math.random() * this.totalPages) + 1;
				}
				
				let randomPage;
				let attempts = 0;
				
				do {
					randomPage = Math.floor(Math.random() * this.totalPages) + 1;
					attempts++;
					
					// 防止无限循环，如果尝试太多次就使用顺序页码
					if (attempts > this.totalPages * 2) {
						for (let i = 1; i <= this.totalPages; i++) {
							if (!this.requestedPages.includes(i)) {
								return i;
							}
						}
						// 如果所有页码都请求过了，返回第一个未请求的页码或随机页码
						return Math.floor(Math.random() * this.totalPages) + 1;
					}
				} while (this.requestedPages.includes(randomPage));
				
				return randomPage;
			},
			
			/**
			 * 获取名片列表 - 优化版
			 * 解决方案：使用随机页码 + 前端去重的方式解决后端随机查询重复数据问题
			 * 1. 生成随机页码请求，避免按顺序1,2,3...查询
			 * 2. 前端维护已显示数据ID集合，过滤重复数据
			 * 3. 使用接口返回的total准确计算总页数
			 * 4. 不需要修改后端接口，完全前端优化
			 */
			getList() {
				// 生成随机页码，避免重复请求
				const randomPage = this.generateRandomPage();
				
				cardList({
					keyword: this.searchVal,
					page: randomPage,
					limit: 16,
				}).then(res => {
					let data = res.data.data || [];
					
					// 使用接口返回的total准确计算总页数
					if (res.data.total !== undefined) {
						this.totalPages = Math.ceil(res.data.total / 16);
						// 如果总页数为0，至少设为1页
						if (this.totalPages === 0) {
							this.totalPages = 1;
						}
					}
					
					// 记录已请求的页码
					if (!this.requestedPages.includes(randomPage)) {
						this.requestedPages.push(randomPage);
					}

					// 过滤已显示的数据，避免重复 (确保item.id存在)
					const newData = data.filter(item => item && item.id && !this.displayedCardIds.includes(item.id));

					if (newData.length === 0) {
						// 如果本次请求没有新数据，增加计数器
						this.noNewDataCount++;
						
						// 如果连续3次都没有新数据，或者已请求页码数达到总页数，认为没有更多数据
						if (this.noNewDataCount >= 3 || this.requestedPages.length >= this.totalPages) {
							this.mpStatus = 'noMore';
						} else {
							// 继续请求下一页
							this.getList();
						}
						return;
					}

					// 重置无新数据计数器
					this.noNewDataCount = 0;

					// 收集新数据的ID
					const newIds = newData.map(item => item.id);
					this.displayedCardIds = [...this.displayedCardIds, ...newIds];

					// 根据是否还有未请求的页码来判断是否还有更多数据
					if (this.requestedPages.length >= this.totalPages) {
						// 所有页码都请求过了，检查是否还能获取新数据
						if (this.displayedCardIds.length >= (res.data.total || 0)) {
							this.mpStatus = 'noMore';
						} else {
							// 重置已请求页码，开始新一轮随机请求
							this.requestedPages = [];
							this.mpStatus = 'more';
						}
					} else {
						this.mpStatus = 'more';
					}

					// 添加新数据到列表
					this.cardDataList = [...this.cardDataList, ...newData];
				}).catch(err => {
					console.error('获取名片列表失败:', err);
					this.mpStatus = 'more'; // 发生错误时保持可以继续加载的状态
				});
			},

			getListSearch() {
				// 重置分页相关数据，开始新的搜索
				this.resetPaginationData();
				
				cardList({
					keyword: this.searchVal,
					page: 1,
					limit: 16,
				}).then(res => {
					let data = res.data.data || [];
					this.cardDataList = data;
					this.cardPage = res.data.current_page || 1;
					
					// 使用接口返回的total准确计算总页数（搜索结果）
					if (res.data.total !== undefined) {
						this.totalPages = Math.ceil(res.data.total / 16);
						// 如果总页数为0，至少设为1页
						if (this.totalPages === 0) {
							this.totalPages = 1;
						}
					}
					
					// 根据搜索结果数量和总页数判断状态
					if (this.totalPages <= 1) {
						this.mpStatus = 'noMore';
					} else {
						this.mpStatus = 'more';
					}
					
					// 收集搜索结果的ID，用于后续去重
					if (data.length > 0) {
						const searchIds = data.filter(item => item && item.id).map(item => item.id);
						this.displayedCardIds = [...searchIds];
						// 记录第一页已请求
						this.requestedPages = [1];
					}
				}).catch(err => {
					console.error('搜索失败:', err);
					this.mpStatus = 'more';
				});
			},
			
			// 重置分页相关数据
			resetPaginationData() {
				this.displayedCardIds = [];
				this.requestedPages = [];
				this.noNewDataCount = 0;
				this.cardPage = 1;
			},
			toMpPage(item) {
				// #ifdef MP-WEIXIN
				uni.requestSubscribeMessage({
					tmplIds: ['isRFUlKxwwU08-0gSBKmsuI7jiPHR7dlbYsCNkpjqTM',
						'6o66cib1Dz28tWRoQKHxfDhuSTIjr30kWTYACHOpzd4',
						'reVE_yMnD9b6eR5S9BKpxfKUG9xfKH7EtMT79SePlsk'
					],
					success(res) {

					}
				})
				// #endif

				if (!this.isLogin) {
					toLogin();
					return;
				}
				uni.navigateTo({
					url: '/pages/extend/connection/index_desc?id=' + item.id
				})
			},

			cardStatusFunc() {
				return new Promise((resolve) => {
					cardUserGetCardStatus().then(res => {
						if (res.status == 200 && res.data) {
							uni.setStorageSync('cardExpireTime', res.data);

							if (res.data && res.data.card_endtime) {
								let cruurenTime = this.$timer.formatTime(Date.now(),
									'yyyy-mm-dd hh:MM:ss');
								let isExpired = this.$timer.isMembershipExpired(cruurenTime, res.data
									.card_endtime);
								// 如果会员未过期且是会员，返回true
								resolve(!isExpired && res.data.is_card == 1);
							} else {
								// 没有结束时间或不是会员
								resolve(false);
							}

						} else {
							resolve(false);
						}
					}).catch(() => {
						resolve(false);
					});
				});
			},
			/**
			 * 判断一下会员是否过期
			 */
			async verifyCardIsExpire() {
				try {
					let data = uni.getStorageSync('cardExpireTime');
					if (data) {
						if (data.is_card == 1) { // 判断一下是否过期了
							let cruurenTime = this.$timer.formatTime(Date.now(), 'yyyy-mm-dd hh:MM:ss');
							let isExpired = this.$timer.isMembershipExpired(cruurenTime, data.card_endtime);
							if (isExpired) {
								// 如果过期了，重新获取会员状态
								return await this.cardStatusFunc();
							}
							return true; // 会员未过期
						} else {
							// 不是会员，重新获取状态确认
							return await this.cardStatusFunc();
						}
					} else {
						// 没有缓存数据，获取会员状态
						return await this.cardStatusFunc();
					}
				} catch (error) {
					console.error('验证会员状态出错:', error);
					return false;
				}
			},
			toPageClick() {

				// 判断登录
				if (!this.isLogin) {
					toLogin();
					return;
				}

				// 不是会员提示
				// this.verifyCardIsExpire().then(isVip => {
				// 	if (!isVip) {
				// 		uni.showModal({
				// 			content: '仅限遇见贵商会员发布',
				// 			confirmText: '开通会员',
				// 			success: (res) => {
				// 				if (res.confirm) {
				// 					uni.navigateTo({
				// 						url: '/pages/extend/user_vip/user_vip'
				// 					})
				// 				}
				// 			}
				// 		})
				// 		return;
				// 	}

				// 	uni.navigateTo({
				// 		url: '/pages/extend/connection/send_need'
				// 	})
				// });

				// 判断是否创建名片 创建了才能发布
				let myCard = uni.getStorageSync('userCardInfo');
				if (myCard && myCard.id > 0) {
					uni.navigateTo({
						url: '/pages/extend/connection/send_need'
					})
				} else {
					uni.showModal({
						content: '至少开通一张免费版名片后才能发布！',
						confirmText: '前往开通',
						cancelText: '暂不考虑',
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/extend/connection/create'
								})
							}
						}
					})
				}


			},
			sendCommonClick() {

				if (!this.inputValu) {
					uni.showToast({
						title: '请输入内容',
						icon: 'none'
					})
					return;
				}

				projectCommentCreate({
					content: this.inputValu,
					re_uid: this.replyComment ? this.replyComment.uid : '',
					project_id: this.currentItem.id,
					type: 2
				}).then(res => {
					this.popupShow = false;
					let userInfo = Cache.get('USER_INFO', true);
					if (res.status == 200) {
						let sendListIndex = this.sendList.findIndex(item => item.id == this.currentItem.id);
						this.sendList[sendListIndex].comment.push({
							id: res.data.id,
							content: this.inputValu,
							re_uid: this.replyComment ? this.replyComment.re_uid : '',
							reuser: this.replyComment ? this.replyComment.reuser : {},
							uid: this.uid,
							user: {
								uid: this.uid,
								nickname: userInfo.nickname || '用户'
							}
						})
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				})


			},
			sheetClose() {
				this.sheetShow = false;
				this.sheetList = [{
						name: '评论',
					},
					// {
					// 	name: '转发',
					// 	openType: 'share'
					// },
				];
			},
			sheetSelect(e) {

				if (e.name == '评论') {
					if (!this.isLogin) {
						toLogin();
						return;
					}
					this.replyComment = {};
					this.inputValu = '';
					this.placeholder = `请输入内容！`;
					this.popupShow = true;
					this.$nextTick(() => {
						this.popupFocus = true;
					})
					return
				}

				if (e.name == '删除') {
					if (!this.isLogin) {
						toLogin();
						return;
					}
					this.sheetList = false;
					projectCommentDelete({
						id: this.replyComment.id,
					}).then(res => {
						if (res.status == 200) { // 删除页面数据
							let sendListIndex = this.sendList.findIndex(item => item.id == this.currentItem.id);
							let replyIndex = this.sendList[sendListIndex].comment.findIndex(item => item.id == this
								.replyComment.id);
							this.sendList[sendListIndex].comment.splice(replyIndex, 1);
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
					})

				}
			},
			extendClick(item) {
				this.sheetShow = true;
				this.currentItem = item
			},
			replyCommont(item, cur) {
				this.replyComment = cur;
				this.currentItem = item

				if (cur.uid == this.uid) {
					this.sheetList = [{
						name: '删除'
					}];
					this.sheetShow = true;
					return
				}
				this.inputValu = '';
				this.placeholder = `回复 ${cur.user.nickname}`;
				this.popupShow = true;
				this.popupFocus = true;
			},
			followClick(tag, item) {
				if (tag == '收藏') {
					cardRelationCreate({
						type_id: item.id,
						type: 15
					}).then(res => {
						if (res.status == 200) {
							item.is_follow = 1;
							item.follow_num++
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
					})
				} else {
					cardRelationDelete({
						type_id: item.id,
						type: 15
					}).then(res => {
						if (res.status == 200) {
							item.is_follow = 2;
							item.follow_num--
						} else {
							uni.showToast({
								title: res.message,
								icon: 'none'
							})
						}
					})
				}
			},
			cardCardInfoLikeFunc(item) {
				cardCardInfoLike({
					id: item.id
				}).then(res => {
					if (res.status == 200) {
						item.like_num++;
					}
				})
			},
			cardCardInfoListFunc() {
				this.status = 'loading';
				cardCardInfoList({
					type: '',
					industry: '',
					keyword: this.form.search,
					limit: 10,
					page: this.sendPage.current_page
				}).then(res => {
					let data = res.data.data;
					this.sendPage.current_page = res.data.current_page;
					if (data.length < 6) {
						this.status = 'noMore'
					} else {
						this.status = 'more'
					}
					this.sendList = [...this.sendList, ...data];
					uni.stopPullDownRefresh();
				})
			},
			cardCardInfoListSearchFunc() {
				this.status = 'loading';
				cardCardInfoList({
					type: '',
					industry: '',
					keyword: this.searchVal,
					limit: 10,
					page: this.sendPage.current_page
				}).then(res => {
					this.status = 'more';
					this.sendList = res.data.data;
					this.sendPage.current_page = res.data.current_page;
				})
			},

			// 切换标签
			switchTab(index) {
				this.activeTab = index;
				
				// 切换到贵商人脉时，重置分页数据以获取全新的随机内容
				if (index === 1) {
					this.resetPaginationData();
					this.cardDataList = [];
					this.mpStatus = 'loading';
					this.getList();
				}
			}
		},
		onReachBottom() {
			if (this.activeTab == 0) {
				if (this.status == 'noMore') return;
				this.sendPage.current_page++;
				this.cardCardInfoListFunc();
			}
			if (this.activeTab == 1) {
				if (this.mpStatus == 'noMore') return;
				// 使用随机页码策略，不需要手动增加页码
				this.getList();
			}
		},
		onLoad() {
			this.getNav();
			// 初始化时重置分页数据
			this.resetPaginationData();
			this.getList();
			this.cardCardInfoListFunc();
		},
		// #ifdef MP
		onShareAppMessage: function() {
			let that = this;
			let pathUrl = this.path + `?uid=${that.uid || -1}&id=${0}`;
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			});
			return {
				title: this.activeTab == 0 ? '商机广场' : '贵商人脉',
				imageUrl: "",
				path: pathUrl
			};
		},
		onShareTimeline: function() {
			let that = this;
			return {
				title: this.activeTab == 0 ? '商机广场' : '贵商人脉',
				query: {
					uid: this.uid || -1
				},
				imageUrl: ''
			};
		},
		// #endif
		onShow() {
			let data = uni.getStorageSync('tabberQuery');
			if (data.index == 1) {
				this.activeTab = data.data
			}


		},
		created() {
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route //获取当前页面路由
			this.activeRouter = '/' + curRoute
		},
		onReady() {
			// #ifdef MP-WEIXIN
			this.$nextTick(function() {
				// #ifdef MP
				const menuButton = uni.getMenuButtonBoundingClientRect();
				const query = uni.createSelectorQuery().in(this);
				query
					.select('#home')
					.boundingClientRect(data => {
						this.homeTop = menuButton.top * 2 + menuButton.height - data.height;
					})
					.exec();
				// #endif
			});
			// #endif
		},
	}
</script>

<style scoped lang="scss">
	.box-create {
		font-size: 28rpx;
		text-align: center;
		line-height: 60rpx;
		border-top-left-radius: 50rpx;
		border-bottom-left-radius: 50rpx;
		bottom: 300rpx;
		right: 0rpx;
		position: fixed;
		width: 200rpx;
		height: 60rpx;
		background-color: #00009E;
		color: white;
	}

	.box-mp-rq {
		width: 170rpx;
		height: 35rpx;
		background-color: white;
		border-radius: 6rpx;
		margin-left: 20rpx;
	}

	.box-mp-name {
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		bottom: 8rpx;
		left: 0rpx;
		width: 100%;
		height: 50rpx;
		background-color: #1D46BC;
		border-top-right-radius: 30rpx;
		border-top-left-radius: 30rpx;
	}

	.box-mp {
		margin-bottom: 20rpx;
		margin-left: 20rpx;
		padding: 10rpx;
		border-radius: 12rpx;
		height: 500rpx;
		width: 349rpx;
		background-color: white;
	}

	.box-mp-name {
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		bottom: 8rpx;
		left: 0rpx;
		width: 100%;
		height: 50rpx;
		background-color: #1D46BC;
		border-top-right-radius: 30rpx;
		border-top-left-radius: 30rpx;
	}

	.box-img-for {
		display: flex;
		flex-wrap: wrap;
	}

	.box-fast {
		text-align: center;
		font-size: 28rpx;
		line-height: 60rpx;
		width: 140rpx;
		height: 60rpx;
		box-sizing: border-box;
		background-color: #E1E1FC;
		color: #00009E;
		font-weight: bold;
		border-radius: 6rpx;
	}

	.box-gxfb {
		z-index: 999;
		position: fixed;
		right: 20rpx;
		bottom: 220rpx;
		border-radius: 100%;
	}

	.box-xq {
		border-radius: 6rpx;
		border: 1rpx solid #00009E;
		color: #00009E;
		font-weight: bold;
		text-align: center;
		font-size: 26rpx;
		width: 80rpx;
		height: 40rpx;
		background-color: #F1F1FF;
	}

	.box-moreM {
		text-align: center;
		line-height: 40rpx;
		width: 60rpx;
		height: 40rpx;
		background-color: #F5F5F5;
		border-radius: 6rpx;
	}

	.sentCommon:active {
		opacity: .5;
	}

	.sentCommon {
		border-radius: 12rpx;
		margin-left: 20rpx;
		width: 120rpx;
		height: 65rpx;
		background-color: #00009E;
		color: white;
		text-align: center;
		line-height: 65rpx;
	}


	.box-logo {
		width: 276rpx;
		height: 70rpx;
	}

	.head-wrapper {
		z-index: 999;
		position: fixed;
		top: 0;
		margin-left: 20rpx;
	}

	.box-main-top {
		background-color: white;
		position: fixed;
		top: 0rpx;
		left: 0rpx;
		width: 100%;
		z-index: 99;
	}

	// 标签样式
	.tab-container {
		border-bottom: 2rpx solid #CCCCCC;
		display: flex;
		width: 100%;
		background-color: #fff;
	}

	.tab-item {
		flex: 1;
		text-align: center;
		font-size: 32rpx;
		height: 88rpx;
		line-height: 88rpx;
		position: relative;
		color: #333;
	}

	.active {
		font-weight: bold;
		color: #000;
	}

	.tab-line {
		position: absolute;
		bottom: -1px;
		left: 50%;
		transform: translateX(-50%);
		width: 50%;
		height: 15rpx;
		background-color: #01009C;
		border-radius: 0;
		border-top-right-radius: 20rpx;
		border-top-left-radius: 20rpx;
	}

	.tab-content {
		// padding: 20rpx;
	}

	.search-box {
		display: flex;
		align-items: center;
		width: 100%;
		padding: 30rpx 40rpx;
		box-sizing: border-box;
		margin-bottom: 20rpx;
		background-color: #FFFFFF;
	}

	.search-input {
		width: 100%;
		height: 80rpx;
		background-color: #F5F5F5;
		border-radius: 40rpx;
		padding: 0 30rpx;
		font-size: 28rpx;
		box-sizing: border-box;
	}
</style>